package com.sniper.springmvc.redis;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Enumeration;

/**
 * Created by suzhen on 2017/3/17.
 */
public class RedisSessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("session创建");
        System.out.println("id:" + se.getSession().getId());
        HttpSession session = se.getSession();
        Enumeration<String> names = session.getAttributeNames();
        System.out.println("---->");
        while (names.hasMoreElements()){
            String name = names.nextElement();
            System.out.println(name + ":" + session.getAttribute(name));
        }

        System.out.println("<----");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("session销毁");
        System.out.println("id:" + se.getSession().getId());
        HttpSession session = se.getSession();
        Enumeration<String> names = session.getAttributeNames();
        System.out.println("---->");
        while (names.hasMoreElements()){
            String name = names.nextElement();
            System.out.println(name + ":" + session.getAttribute(name));
        }

        System.out.println("<----");
    }
}
